package com.mcptt.config.body;

import com.cloudptt.api.product.func.call.CallAttr;
import com.cloudptt.api.product.log.Log;

import java.io.UnsupportedEncodingException;

public class XCapBodyGms {

	private String[] groupIdArray = null;

	public XCapBodyGms(String[] groupIdArray)
	{
		Log.debug(this.getClass(),"groupIdArray = " + groupIdArray);
		this.groupIdArray = groupIdArray;
	}

	public String toString()
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\r\n");
		strBuff.append("<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">").append("\r\n");
		strBuff.append("<list>").append("\r\n");
		;
		if(groupIdArray != null
				&& groupIdArray.length > 0)
		{
			for(int i = 0; i < groupIdArray.length;i++)
			{
				String groupId = groupIdArray[i];
				if(groupId != null) {
					strBuff.append("<entry ").append("uri=\"").append("org.openmobilealliance.groups/global/byGroupID/").append(groupId).append("\"/>").append("\r\n");
				}
			}
		}

		strBuff.append("</list>").append("\r\n");
		strBuff.append("</resource-lists>");

		try {
			return new String(strBuff.toString().getBytes(),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return strBuff.toString();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
